﻿Ext.define('app.prm.synth.CreateOrEdit',
{
    extend: 'Ext.window.Window',
    autoScroll: true,
    modal: true,
    width: 800,
    height: 600,
    layout: 'fit',
    ProjectId: 0,
    SynthId: 0,
    initComponent: function () {
        var me = this;
        me.items = [me.getForm()];
        me.buttons = [
            { text: '保存', scope: this, handler: me.onSubmit },
            { text: '关闭', handler: function () { me.close(); } }
        ];
        me.callParent();
    },
    listeners: {
        afterrender: function (me) {
            if (me.SynthId > 0) {
                App.AjaxGet('/api/services/app/synthesis/Get?synthId=' + me.SynthId, function (data) {
                    me.getForm().getForm().setValues(data.result);
                    me.scheme.cdx = data.result.cdx;
                    me.scheme.img = data.result.imageBase;
                    me.scheme.showImg();
                });
            }
        }
    },
    getForm: function () {
        var me = this;
        if (!this.form) {
            this.form = new Ext.form.Panel({
                defaultType: 'textfield',
                border: false,
                defaults: { anchor: '100%' },
                fieldDefaults: {
                    labelAlign: "top",
                    flex: 1,
                    margin: 6
                },
                items: [
                    {
                        hidden: true,
                        name: 'id',
                        value: 0
                    },
                    {
                        hidden: true,
                        name: 'projectId',
                        value: me.ProjectId
                    },
                    {
                        hidden: true,
                        name: 'imageBase',
                        value: ''
                    },
                    {
                        hidden: true,
                        name: 'cDX',
                        value: ''
                    },
                    {
                        fieldLabel: '路线名称',
                        name: 'synthName'
                    },
                    {
                        xtype: 'textarea',
                        fieldLabel: '描述',
                        name: 'remark'
                    },
                    me.getSchemePanel()
                ]
            });
        }
        return this.form;
    },
    getSchemePanel: function () {
        if (!this.scheme) {
            this.scheme = Ext.create('app.ux.GSE.gsePanel', {
                style: 'margin: 5px 5px 5px 5px',
                fieldLabel: '路线',
                height: 360
            })
        }
        return this.scheme;
    },
    onSubmit: function () {
        var me = this;
        var forms = this.getForm().getForm().getValues();
        forms.CDX = me.scheme.cdx;
        forms.ImageBase = me.scheme.img;
        App.AjaxPost('/api/services/app/synthesis/CreateOrEdit', forms, function () {
            me.fireEvent("savesuccess");
        });
    }
});